package com.nfit.shopweb.web.api;

import com.nfit.shopmodel.entity.system.SysMenu;
import com.nfit.shopmodel.vo.common.Result;
import com.nfit.shopmodel.vo.common.ResultCodeEnum;
import com.nfit.shopmodel.vo.system.SysMenuVo;
import com.nfit.shopweb.service.SysMenuService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:SysMenuController
 * Package:com.nfit.shopweb.web.api
 * Description
 *
 * @Author L
 * @Create 2024/11/19 19:22
 */
@Tag(name = "menu",description = "左侧菜单管理")
@RestController
@RequestMapping("/api/menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     *查询所有树形菜单
     * @return 树形菜单
     */
    @GetMapping("/menuList")
    public Result menuList() {
        List<SysMenu> list = sysMenuService.menuList();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询查询用户的所对应菜单列表
     * @return 返回用户的所对应菜单列表
     */
    @GetMapping("/findUserMenu")
    public Result findUserMenu() {
        List<SysMenuVo> list = sysMenuService.findUserMenu();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加菜单
     * @param sysMenu 菜单实体
     */
    @PostMapping("/save")
    public Result save(@RequestBody SysMenu sysMenu){
        sysMenuService.save(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改菜单
     * 根据实体里面专递的id作为条件
     * @param sysMenu 菜单实体
     */
    @PutMapping("/update")
    public Result update(@RequestBody SysMenu sysMenu){
        sysMenuService.update(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据id删除菜单
     * @param id 菜单id
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        sysMenuService.delete(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


}
